package com.qzimp.fujiancuo.service.impl;

import com.qzimp.fujiancuo.entity.Email;
import com.qzimp.fujiancuo.exceptions.ApiException;
import com.qzimp.fujiancuo.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailServiceImpl implements EmailService {
    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.username}")
    private  String mailSender;
    @Override
    public void sendMail(Email email) throws ApiException {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(mailSender);
        // 邮件接收人
        mailMessage.setTo(email.getUser());
        // 邮件主题
        mailMessage.setSubject(email.getSubject());
        // 邮件内容
        mailMessage.setText(email.getContent());
        //抄送
//        mailMessage.setCc(mailSender);
        javaMailSender.send(mailMessage);
    }
}
